<?php

namespace app\errorCode;

/**
 * 状态码集合
 *
 * user ：Du
 * Date : 2022/1/8
 * Time : 10:30
 * Class Code
 * projects\errorCode
 */
class Code
{

    static $code = [
        'success' => ['code' => 0, 'message' => '请求成功'],
        'fail' => ['code' => 1, 'message' => '%s'],
        'error' => ['code' => 99, 'message' => '程序出错'],
        'empty' => ['code' => 1, 'message' => '%s不能为空'],

        //常用
        'addFail' => ['code' => 1, 'message' => '添加失败'],
        'updateFail' => ['code' => 1, 'message' => '更新失败'],
        'deleteFail' => ['code' => 1, 'message' => '删除失败'],
        'noData' => ['code' => 1, 'message' => '数据不存在'],

        //上传
        'typeError' => ['code' => 1, 'message' => '类型错误'],
        'sizeError' => ['code' => 1, 'message' => '大小错误'],
    ];

    /**
     * 获取定义的状态信息
     *
     * User : Du
     * Date : 2022/1/8
     * Time : 10:41
     * @param string $key
     * @param string $text
     * @return array
     */
    public static function codeData(string $key = '', string $text = ''): array
    {
        $code = self::$code[$key];
        if ($text != '') {
            $code['message'] = sprintf($code['message'], $text);
        }
        return $code;
    }
}